package cn.tank.data.sync.core;


import cn.tank.data.sync.core.common.Constants;
import cn.tank.data.sync.core.common.Message;
import cn.tank.data.sync.core.common.Subscriber;

public interface MessageAcceptService {
    default void receiveMessage(String channel, Subscriber subscriber, Message message) {
        if (message == null || message.getDataType() == null) {
            return;
        }
        switch (message.getDataType()) {
            case Constants.WRITE:
                subscriber.write(channel, message.getData());
                break;
            case Constants.UPDATE:
                subscriber.update(channel, message.getData());
                break;
            case Constants.DELETE:
                subscriber.delete(channel, message.getData());
                break;
            case Constants.REFRESH:
                subscriber.refresh(channel);
                break;
            default:
                break;
        }
    }
}
